package com.wxzz.elearing.course.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.course.dto.EnterpriseCurriculumDto;
import com.wxzz.elearing.course.dto.UserCurriculumStatisticsDataDto;
import com.wxzz.elearing.course.entity.WxUserCurriculumStatisticsData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface WxUserCurriculumStatisticsDataMapper extends BaseMapper<WxUserCurriculumStatisticsData> {


    List<WxUserCurriculumStatisticsData> selectSumByStudyTime(@Param("enterpriseId") Long enterpriseId, @Param("userCurriculumStatisticsDataDto") UserCurriculumStatisticsDataDto userCurriculumStatisticsDataDto);

    @Select("SELECT\n" +
            "\tsave_time saveTime,\n" +
            "\tSUM( study_time ) studyTime\n" +
            "FROM\n" +
            "\t`wx_user_curriculum_statistics_data` \n" +
            "WHERE\n" +
            "\tcurriculum_id = #{curriculumId} \n" +
            "\tAND enterprise_id = #{enterpriseId} \n" +
            "\tAND save_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "\tAND deleted = 0\n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time")
    List<EnterpriseCurriculumDto> listEnterpriseCurriculumDto(@Param("curriculumId") Long curriculumId, @Param("enterpriseId") Long enterpriseId, @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tsave_time saveTime,\n" +
            "\tSUM( study_time ) studyTime\n" +
            "FROM\n" +
            "\t`wx_user_curriculum_statistics_data` \n" +
            "WHERE\n" +
            "\tcurriculum_id = #{curriculumId} \n" +
            "\tAND save_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "\tAND deleted = 0\n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time")
    List<EnterpriseCurriculumDto> listCurriculumDto(@Param("curriculumId") Long curriculumId,  @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tSUM( study_time ) studyTime,\n" +
            "\tsave_time saveTime \n" +
            "FROM\n" +
            "\t`wx_user_curriculum_statistics_data` \n" +
            "WHERE\n" +
            "\twx_user_id = #{wxUserId} \n" +
            "\tAND deleted = 0 \n" +
            "\tAND save_time BETWEEN #{startTime} AND #{endTime}\n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time ASC")
    List<EnterpriseCurriculumDto> listWxUserCurriculumDto(@Param("wxUserId") Long wxUserId, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
